/**
 * Class: Resources
 * <p/>
 * Purpose: Resource accessor
 *
 * @author Ken
 */

package org.openfantasia.rsrc;

import org.openfantasia.util.FileUtils;

import javax.swing.*;
import java.awt.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.IOException;

public class Resources {

	public static ImageIcon getImageIcon(String... path) {
		String p = pathToPath(path);
		return new ImageIcon(Resources.class.getResource(p));
	}


	public static Image getImage(String... path) {
		return getImageIcon(path).getImage();
	}


	public static String getString(String... path) throws IOException {
		return FileUtils.readTextFromStream(getInputStream(path));
	}


	public static InputStream getInputStream(String... path) {
		String p = pathToPath(path);

		return Resources.class.getResourceAsStream(p);
	}


	public static Reader getReader(String... path) {
		return new InputStreamReader(getInputStream(path));
	}


	private static String pathToPath(String... path) {
		String p = "";

		for (int i = 0; i < path.length; i++) {
			p += path[i];
			if (i < (path.length - 1)) {
				p += "/";
			}
		}
		return p;
	}
}
